package function;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelBook implements IFunction{
    public void act(BookList bookList){
        System.out.println("删除书籍:");
        Scanner s = new Scanner(System.in);
        int currentSize = bookList.getBookNum();
        System.out.println("请输入书籍名字：");
        String bookName = s.nextLine();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(bookName.equals(book.getBookName())){
                book= bookList.getBook(i + 1);
                bookList.setBook(book, i);
                bookList.setBookNum(currentSize - 1);
                System.out.println("删除完成");
                return;
            }
        }
        System.out.println("删除失败：没有这本书");
    }
}
